import bb.cascades 1.2
import bb.system 1.2

Sheet {
    id: root
    signal start()
    onClosed: {
        root.destroy();
    }
    
    
    Page {
        id: page
        property variant helden: undefined
        titleBar: TitleBar {
            dismissAction: ActionItem {
                imageSource: "asset:///images/icons/bb10/ic_previous.png"
                onTriggered: {
                    root.close();
                }
            }
            acceptAction: ActionItem {
                enabled: false
                id: actionAccept
                imageSource: "asset:///images/icons/bb10/ic_nav_to.png"
                onTriggered: {
                    root.start();
                    root.close();
                }
            }
        }
        
        Container {
            ListView {
                property variant layoutFrame
                //dataModel: contactsmodel
                dataModel: contactManager.contacts
                id: heldenlist
                horizontalAlignment: HorizontalAlignment.Fill
                verticalAlignment: VerticalAlignment.Fill
                listItemComponents: [
                    ListItemComponent {
                        type: "item"
                        HeldenListitem {
                            id: listitem
                            title: ListItemData.name.toString()
                            favourite: ListItemData.favourite
                            checked: ListItemData.favourite
                            favouriteDisabled: true
                            checkable: true
                            onCheckedChanged: {
                                ListItem.view.updateHelden(ListItemData.phone.toString(), listitem.checked);
                            }
                            onCreationCompleted: {
                                ListItem.view.updateHelden(ListItemData.phone.toString(), listitem.checked);
                            }
                        }
                    }
                ]
                attachedObjects: [
                    LayoutUpdateHandler {
                        onLayoutFrameChanged: {
                            heldenlist.layoutFrame = layoutFrame;
                        }
                    }
                ]
                function updateHelden(phone, active) {
                    var size = locationHandler.onRouteUpdateHelden(phone, active);
                    actionAccept.enabled = size > 0;
                }
            }
        }
   
    }
}
